package com.fwzc.giuseppe.base;

import android.app.Activity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.fwzc.giuseppe.R;
import com.fwzc.giuseppe.config.Config;
import com.fwzc.giuseppe.config.UserInfo;
import com.fwzc.giuseppe.util.FileHelper;
import com.fwzc.giuseppe.util.PhoneHelper;
import com.nostra13.universalimageloader.core.ImageLoader;


public class BaseActivity extends FragmentActivity{
//	protected MyProgressDailog progressDialog;
	protected RelativeLayout bg_actionbar_side;
    protected TextView actionbar_side_name;
	protected TextView tv_actionbar_side_right;
    protected TextView tv_actionbar_side_left;
		
    protected ImageView iv_actionbar_side_right;
	protected ImageView iv_actionbar_side_left;
	
	protected int width;
	
	protected FileHelper fileHelper,fileHelperCache;
    private Toast mToast;
	protected ImageLoader imageLoader = ImageLoader.getInstance();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initstore();
//		progressDialog=new MyProgressDailog(this, R.style.progress_dialog);
		//获取屏幕的宽度
		width=PhoneHelper.getScreenWidth(this);
//		setViews();
//		myApplication=(MyApplication)getApplication();
	}
//	/**
//	 * 设置公用内容;
//	 */
//	private void setViews() {
//		progressDialog=new MyProgressDailog(this, R.style.progress_dialog);
//	}
    public void initBar(){
    	bg_actionbar_side = (RelativeLayout) findViewById(R.id.bg_actionbar_side);
	    actionbar_side_name = (TextView) findViewById(R.id.actionbar_side_name);
	    tv_actionbar_side_right = (TextView) findViewById(R.id.tv_actionbar_side_right);
	    tv_actionbar_side_left = (TextView) findViewById(R.id.tv_actionbar_side_left);
	    iv_actionbar_side_right = (ImageView) findViewById(R.id.iv_actionbar_side_right);
	    iv_actionbar_side_left = (ImageView) findViewById(R.id.iv_actionbar_side_left);
	    actionbar_side_name.setVisibility(View.VISIBLE);
	  
	}
	/**
	 * 初始化sharedpeforence
	 */
	private void initstore(){
		fileHelper = new FileHelper(getBaseContext(),Config.file_userLoginedInfo);
		fileHelperCache = new FileHelper(getBaseContext(),Config.file_temporary);
	}
	/**
	 * Toast
	 * @param message
	 */
	public void showToast(Object message) {
		
		if(!TextUtils.isEmpty(String.valueOf(message))){
			if (null == mToast) {
				
				if(message instanceof Integer){
					mToast = Toast.makeText(this, (Integer) message, Toast.LENGTH_SHORT);
				}else if(message instanceof String){
					mToast = Toast.makeText(this, (String)message, Toast.LENGTH_SHORT);
				}
				mToast.setGravity(Gravity.CENTER, 0, 0);
			} else {
				
				if(message instanceof Integer){
					mToast.setText((Integer)message);
				}else if(message instanceof String){
					mToast.setText((String)message);
				}
				
			}
			
			mToast.show();
			
		}
		
	}
	/**
	 * 判断网络是否链接  
	 * @param paramActivity
	 * @return
	 */
	protected  boolean hasInternet(Activity paramActivity) {
		ConnectivityManager localConnectivityManager = (ConnectivityManager) paramActivity
				.getApplicationContext().getSystemService("connectivity");
		boolean ret = false;
		if (localConnectivityManager == null) {
			return ret;
		}
		NetworkInfo[] arrayOfNetworkInfo = localConnectivityManager
				.getAllNetworkInfo();
		if (arrayOfNetworkInfo != null)
			;
		for (int j = 0; j < arrayOfNetworkInfo.length; j++) {
			if (arrayOfNetworkInfo[j].getState() == NetworkInfo.State.CONNECTED) {
				ret = true;
				break;
			}
		}
		return ret;
	}
	 /**
	 * 清除登录信息
	 */
	protected void clearLogininfo() {
		
		fileHelper.putShareProf(UserInfo.USERINFO_USERID, "");
//		fileHelper.putShareProf(UserInfo.USERINFO_BABYID, "");
		fileHelper.putShareProf(UserInfo.USERINFO_USERNAME, "");
		

//		FileHelper.deletedSpFile(this, Config.file_userLoginedInfo);
//		FileHelper.deletedSpFile(this, FileHelper.file_userConfig);
//		FileHelper.deletedSpFile(this, FileHelper.file_userAddress);
//		ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
//		am.killBackgroundProcesses(getPackageName());
		

	}
}
